package com.atguigu.spzx.manager.config;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author yaya
 * @Create 2024/5/28 15:37
 * Description:
 */
@Configuration
public class Knife4jConfiguration {

    @Bean
    public OpenAPI customOpenAPI() {

        return new OpenAPI().info(
                        new Info()
                                .title("后台管理系统API")
                                .version("1.0")
                                .contact(new Contact().name("yaya").email("yayasamaxxx@gmail.com"))
                                .description("后台管理系统API"))
                .components(new Components()
                        .addSecuritySchemes("access_token", new SecurityScheme()
                                .type(SecurityScheme.Type.APIKEY)
                                .in(SecurityScheme.In.HEADER)
                                .name("access_token")));
    }

    @Bean
    public GroupedOpenApi systemAPI() {

        return GroupedOpenApi.builder().group("系统信息管理")
                .addOperationCustomizer(
                        (operation, handlerMethod) ->
                                operation.addSecurityItem(new SecurityRequirement()
                                        .addList("access_token")))
                .pathsToMatch("/admin/system/**")
                .build();
    }

}